<?php
namespace WebAdmin\Controller;
use WebAdmin\Controller\BaseController;
class LoginController extends BaseController {
    public function index(){
        if(!empty($_POST)) {
            $AdminModel = D("Admin");
            if (!$AdminModel->autoCheckToken($_POST)){
                $this->error('表单验证失败！');
            }else {
                $rs = $AdminModel->where("login_name='" . I('post.username', '', 'htmlspecialchars') . "'")->select();
                if (empty($rs[0])) {
                    $this->error('该用户不存在！');
                } elseif ($rs[0]['login_pass'] == md5(I('post.password', '', 'htmlspecialchars'))) {
                    $_SESSION['is_admin'] = 1;
                    $_SESSION['real_name'] = $rs[0]['real_name'];
                    $_SESSION['login_name'] = $rs[0]['login_name'];
                    $this->success("登入成功!", __APP__ . "/index.php");
                } else {
                    $this->error("密码不正确！");
                }
            }
        }else {
            $data['title'] = '后台登录';
            //$data['index']='index_index';
            $this->assign("data", $data);
            $this->display();
        }
    }

    //安全退出
    public function logout()
    {
        session_destroy();
       header("Content-type: text/html; charset=utf-8");
        echo "<script>alert('您已经安全退出');window.location.href='".__APP__."/index.php/Login';</script>";exit;
    }
}